package com.yang.job.admin.infra.job.thread;


import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

public class YangJobThreadFactory implements ThreadFactory {
    private String poolName;

    private String threadPrefixName;

    private static AtomicInteger poolNumber = new AtomicInteger(1);

    private AtomicInteger threadNumber = new AtomicInteger(1);

    public YangJobThreadFactory(String poolName) {
        this.poolName = poolName;
        this.threadPrefixName = poolName + "-pool-" + poolNumber.getAndIncrement() + "-thread-";
    }

    public String getPoolName() {
        return this.poolName;
    }

    @Override
    public Thread newThread(Runnable r) {
        return new Thread(r, this.threadPrefixName + threadNumber.getAndIncrement());
    }

}

